home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------+
- | INTENSE.C |
- | This piece of code demonstrates how to use text-mode attributes |
- | with backgrounds of 16 possible colors. You may then use the |
- | blink-bit of the text attribute as an intensity bit. |
- | |
- | A text attribute is a byte that contains information on the |
- | foreground and background colors of text-mode characters. The |
- | lower 4 bits (bits 0-3) of the text attribute control the |
- | foreground color, or the color of the text, itself, while the |
- | next 3 bits (bits 4-6) control the color of the background. |
- | The uppermost bit, (bit 7) is used as a blink bit. Normally, |
- | when bit 7 is set, the foreground character blinks. |
- | |
- | Because the foreground has 4 bits to describe itself, there are |
- | sixteen possible colors. Bits 0-2 provide for 8 basic, normal |
- | intensity colors, and bit 3 is an intensity bit that turns the |
- | 8 basic colors into high-intensity colors. |
- | |
- | Because the background has 3 bits dedicated to it, the background |
- | is limited to the 8 normal intensity colors. There is a way, how- |
- | ever, to tell a graphics adapter to interpret the 7th bit |
- | as an intensity bit for the background the same way that bit 3 is |
- | interpreted as an intensity bit for the foreground. |
- | |
- | For CGA adapters, set bit 5 of the CGA Mode Selection Register |
- | at port address 3D8h to zero for high-intensity backgrounds. To |
- | return to blinking backgrounds, set bit 5 to 1. |
- | |
- | For EGA/VTA adapters, call interrupt 10h, function 10h, sub- |
- | function 03h: |
- | Input: AH=10h |
- | AL=03h |
- | BL=0 for high-intensity background |
- | BL=1 for blinking background |
- | |
- | For more information about text attributes, see the description |
- | of function textattr() in the Borland Runtime Library reference. |
- | |
- | Warning! This code has been tested on CGA, EGA, and VGA adapters. |
- | I don't know what would happen with other adapter types (eg, MCGA, |
- | 8514, monochrome). Let me know what happens. |
- | |
- | Author: Ron Gee, [71460,551] |
- | Date: 6/19/92 |
- +---------------------------------------------------------------------*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <graphics.h> /* detect the type of graphics adapter */
- #include <conio.h>
- #include <dos.h>
-
- #define VIDEO 0x10
- #define CGA_VID_PORT 0x03d8
- #define NO_BLINK 0x09
- #define YES_BLINK 0x41
-
- int main()
- {
- int gdriver, gmode;
- union REGS regs;
-
- /* detect the type of graphics driver present */
- detectgraph(&gdriver, &gmode);
-
- if (gdriver == grNotDetected)
- {
- printf("NO_BLINK: No graphics adapter detected, gdriver = %d\n",
- gdriver);
- exit(8);
- }
-
- textattr(0x2F);
- clreol();
- cprintf("Text should be bright white on normal green background");
- textattr(0x1E);
- cprintf("\n\rText should be yellow on normal blue background");
- textattr(0x4A);
- cprintf("\n\rText should be bright green on normal red background");
-
- /* Set the blink bit to be an intensity bit */
- switch (gdriver)
- {
- case CGA:
- outportb(CGA_VID_PORT, NO_BLINK);
- break;
- case EGA:
- case VGA:
- regs.h.ah = 0x10;
- regs.h.al = 0x03;
- regs.h.bl = 0x00;
- int86(VIDEO, ®s, ®s);
- break;
- default:
- printf("\nWarning: Graphics adapter must be CGA, EGA, or VGA"
- " for intense background\n");
- break;
- }
-
- textattr(0xA5);
- cprintf("\n\rText should be magenta on bright green background");
- textattr(0x9E);
- cprintf("\n\rText should be yellow on bright blue background");
- textattr(0xCE);
- cprintf("\n\rText should be yellow on bright red background");
-
- return(0);
- }
-